﻿using System;
using System.IO;
using Autofac;
using MT.Job.Core;
using MT.Job.Core.Extensions;
using Topshelf;
using Topshelf.Autofac;

namespace MT.Job.Task
{

    //Tips 发布的时候选择独立部署
    class Program
    {
        static void Main(string[] args)
        {
            var builder = new ContainerBuilder()
                .ConfigureQuartz()
                .ConfigureAutoMapper()
                .ConfigureSelf();
            var container = builder.Build();
            HostFactory.Run(x =>
            {
                x.SetDisplayName(Settings.Instance.ServiceDisplayName);
                x.SetServiceName(Settings.Instance.ServiceName);
                x.SetDescription(Settings.Instance.ServiceDescription);
                x.UseNLog();
  
                x.UseAutofacContainer(container);

                x.Service<SampleSchedule>(setting =>
                {
                    setting.ConstructUsingAutofacContainer();
                    setting.ConstructUsing(name => new SampleSchedule(container));
                    setting.WhenStarted(async tc => await tc.Start());
                    //setting.WhenStarted(tc => tc.Start());
                    setting.WhenStopped(tc => tc.Stop());
                });
                x.RunAsLocalSystem();
            });
        }
    }
}
